﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TicketM.Configuration
{
    public partial class Products : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["sProject"].ToString() == "" || Session["sProject"] == null)
            {
                Session.Add("refPage", HttpContext.Current.Request.Url);
                Response.Redirect("ProjectSelection.aspx");
            }
            lblProject.Text = Session["sProject"].ToString();
        }

        protected void AddNewProductButton_Click(object sender, EventArgs e)
        {
            TicketM.Models.Tickets ticket = new Models.Tickets();
            if (NewProduct.Text != "")
            {
                try
                {
                    Result.Text = ticket.SetProductsList(NewProduct.Text, Session["sProject"].ToString());
                    if (Result.Text != "Same named product found")
                        DataList1.DataBind();
                }
                catch (Exception ex)
                {
                    Logger.CreateLogEntry("!!ERROR in Products.aspx.cs while adding a new product:" + ex.Message);
                    Response.Redirect("../CommonErrorPage.aspx");
                }
            }
        }
    }
}